using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Ec.NETCoreFramework.Common.Plug.QuartzService
{
    public class Worker : BackgroundService
    {
        private readonly ILogger<Worker> _logger;
        private readonly IServiceCollection _services;

        public Worker(ILogger<Worker> logger, IServiceCollection services)
        {
            _logger = logger;
            _services = services;
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            IServiceProvider serviceProvider = _services.BuildServiceProvider();
            //test.run();
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                var schedulerService = serviceProvider.GetService<QuartzHostedService>();
                //await new JobManage().LoadJob();
                await Task.Delay(1000, stoppingToken);
            }
            //_ = Task.Run(() =>
            // new JobManage().LoadJob()
            //    );
            //await new JobManage().LoadJob();
        }
    }
}
